package com.zhiteng.base.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import butterknife.ButterKnife;

public abstract class BaseActivity extends AppCompatActivity {
    private final int NO_REQUEST = -1;
    protected boolean isFinish = false;

    public abstract void loadNetData();

    public abstract void loadLocalData();


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        ButterKnife.bind(this);
        loadNetData();
        loadLocalData();
    }


    protected abstract int getLayoutId();


    public void startActivity(Class<? extends BaseActivity> cls, boolean isFinish) {
        startActivity(cls, NO_REQUEST, isFinish);
    }

    public void startActivity(Class<? extends BaseActivity> cls, int requestCode, boolean isFinish) {
        if (requestCode == -1) {
            startActivity(cls, null, isFinish);
        } else {
            startActivity(cls, null, requestCode, isFinish);
        }
        finish();
    }


    public void startActivity(Class<? extends BaseActivity> cls, Bundle bundle, boolean isFinish) {
        startActivity(cls, bundle, NO_REQUEST, isFinish);
    }


    public void startActivity(Class<? extends BaseActivity> cls, Bundle bundle, int requestCode, boolean isFinish) {
        Intent intent = new Intent();
        intent.setClass(this, cls);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        if (requestCode == NO_REQUEST) {
            startActivity(intent);
        } else {
            startActivityForResult(intent, requestCode);
        }
        if (isFinish) finish();
    }





}
